/*
 ============================================================================
 Name		: FEAppContainer.cpp
 Author	    : Junjie Qu
 Copyright   : Your copyright notice
 Description : Application Container implementation
 ============================================================================
 */

// INCLUDE FILES
#include <coemain.h>
#include "FEAppEditerContainer.h"

#include <BARSREAD.H>
#include <FE_0xE986B88E.rsg>
#include <akniconarray.h>
#include <Icon.mbg>
#include <eikclbd.h>
#include <aknnotewrappers.h>

// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// CFEAppEditerContainer::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CFEAppEditerContainer* CFEAppEditerContainer::NewL(const TRect& aRect)
{
	CFEAppEditerContainer* self = CFEAppEditerContainer::NewLC(aRect);
	CleanupStack::Pop(self);
	return self;
}

// -----------------------------------------------------------------------------
// CFEAppEditerContainer::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CFEAppEditerContainer* CFEAppEditerContainer::NewLC(const TRect& aRect)
{
	CFEAppEditerContainer* self = new (ELeave) CFEAppEditerContainer;
	CleanupStack::PushL(self);
	self->ConstructL(aRect);
	return self;
}

// -----------------------------------------------------------------------------
// CFEAppEditerContainer::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CFEAppEditerContainer::ConstructL(const TRect& aRect)
{
	// Create a window for this application Container
	CreateWindowL();

	iEditor = new (ELeave) CEikEdwin;
	iEditor->ConstructL(EAknEditorFlagDefault, 8, 5000, 20);
	iEditor->SetContainerWindowL(*this);
	iEditor->SetFocus(ETrue);

	iEditor->CreateScrollBarFrameL();
	iEditor->ScrollBarFrame()->SetScrollBarVisibilityL(
			CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);

	// Set the windows size
	SetRect(aRect);

	// Activate the window, which makes it ready to be drawn
	ActivateL();
}

// -----------------------------------------------------------------------------
// CFEAppEditerContainer::CFEAppEditerContainer()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CFEAppEditerContainer::CFEAppEditerContainer()
{

}

// -----------------------------------------------------------------------------
// CFEAppEditerContainer::~CFEAppEditerContainer()
// Destructor.
// -----------------------------------------------------------------------------
//
CFEAppEditerContainer::~CFEAppEditerContainer()
{
	delete iEditor;
}

// -----------------------------------------------------------------------------
// CFEAppEditerContainer::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void CFEAppEditerContainer::Draw(const TRect& /*aRect*/) const
{
	// Get the standard graphics context
	CWindowGc& gc = SystemGc();

	// Gets the control's extent
	TRect drawRect(Rect());

	// Clears the screen
	gc.Clear(drawRect);

	gc.SetBrushColor(KRgbDarkGray);
	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
	gc.DrawRect(drawRect);
}

// -----------------------------------------------------------------------------
// CFEAppEditerContainer::SizeChanged()
// Called by framework when the Container size is changed.
// -----------------------------------------------------------------------------
//
void CFEAppEditerContainer::SizeChanged()
{
	iEditor->SetExtent(TPoint(7, 7), TSize(218, 231));
}

// -----------------------------------------------------------------------------
// CFEAppEditerContainer::HandlePointerEventL()
// Called by framework to handle pointer touch events.
// Note: although this method is compatible with earlier SDKs, 
// it will not be called in SDKs without Touch support.
// -----------------------------------------------------------------------------
//
void CFEAppEditerContainer::HandlePointerEventL(
		const TPointerEvent& aPointerEvent)
{
	// Call base class HandlePointerEventL()
	CCoeControl::HandlePointerEventL(aPointerEvent);
}

/*******************************************************************************
 * @Name:       CountComponentControls 
 * @Author:     Junjie Qu
 * @Purpose:    Gets the number of controls contained in a compound control.
 * @Returns:    The number of component controls contained by this control
 * @Parameters: void
 * @Remarks:    -
 ******************************************************************************/
TInt CFEAppEditerContainer::CountComponentControls() const
{
	return 1; // return nbr of controls inside this container
}

/*******************************************************************************
 * @Name:       ComponentControl 
 * @Author:     Junjie Qu
 * @Purpose:    Gets an indexed component of a compound control.
 * @Returns:    The component control with an index of aIndex
 * @Parameters: aIndex--index of the control
 * @Remarks:    -
 ******************************************************************************/
CCoeControl* CFEAppEditerContainer::ComponentControl(TInt aIndex) const
{
	switch (aIndex)
	{
		case 0:
			return iEditor;
		default:
			return NULL;
	}
}

/*******************************************************************************
 * @Name:       OfferKeyEventL 
 * @Author:     Junjie Qu
 * @Purpose:    Handles key events.
 * @Returns:    Indicates whether or not the key event was used by this control
 * @Parameters: aKeyEvent--The key event
 * @Parameters: aType--The type of key event
 * @Remarks:    -
 ******************************************************************************/
TKeyResponse CFEAppEditerContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,
		TEventCode aType)
{
	if (iEditor != NULL)
	{
		if (iEditor->IsFocused())
		{
			return iEditor->OfferKeyEventL(aKeyEvent, aType);
		}
	}

	return EKeyWasNotConsumed;
}

/*******************************************************************************
 * @Name:       SetEditorFocus 
 * @Author:     Junjie Qu
 * @Purpose:    Sets Editor to have the keyboard focus.
 * @Returns:    void
 * @Parameters: aFocus--The flag of whether set iEditor focus
 * @Remarks:    -
 ******************************************************************************/
void CFEAppEditerContainer::SetEditorFocus(TBool aFocus)
{
	iEditor->SetFocus(aFocus);
}

/*******************************************************************************
 * @Name:       GetEditerCtrl 
 * @Author:     Junjie Qu
 * @Purpose:    Return the pointer of Editor.
 * @Returns:    Pointer of Editor
 * @Parameters: void
 * @Remarks:    -
 ******************************************************************************/
CEikEdwin* CFEAppEditerContainer::GetEditerCtrl()
{
	return iEditor;
}

// End of File
